package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.PianoIndexBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.RANKING)
public class PostRanking extends BaseAsyPost {

    public String userid,teacherid,type,page;
    public PostRanking(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostRankingInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostRankingInfo info = new PostRankingInfo();

            info.code = object.optString("code");

            JSONObject jsonObject = object.optJSONObject("message");
            info.total = jsonObject.optInt("total");
            info.per_page = jsonObject.optInt("per_page");
            info.current_page = jsonObject.optInt("current_page");
            info.last_page = jsonObject.optInt("last_page");

            JSONArray array = jsonObject.optJSONArray("data");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject o = array.optJSONObject(i);

                    PianoIndexBean pianoIndexBean = new PianoIndexBean();
                    pianoIndexBean.setNumber(o.optString("number"));
                    pianoIndexBean.setOrder(o.optString("order"));
                    pianoIndexBean.setUserid(o.optString("userid"));
                    pianoIndexBean.setAvatar(o.optString("avatar"));
                    pianoIndexBean.setColor(o.optString("color"));
                    pianoIndexBean.setId(o.optString("id"));

                    pianoIndexBean.setId(o.optString("id"));
                    info.list.add(pianoIndexBean);
                }

            }


            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostRankingInfo {

        public String code, message;
        public int total, per_page ,current_page,last_page;
        public List<PianoIndexBean> list = new ArrayList<>();
    }

}
